package com.bestom.smartwatch.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bestom.smartwatch.R;
import com.bestom.smartwatch.bean.IconBean;

import java.util.List;

public class IconAdapter extends BaseAdapter {

    public List<IconBean> mList;
    public Context mContext;
    public LayoutInflater mLayoutInflater;
    public IconAdapter(Context context,List<IconBean> list){
        mContext=context;
        mList=list;
        mLayoutInflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView==null){
            viewHolder=new ViewHolder();
            convertView=mLayoutInflater.inflate(R.layout.pop_item,null);
            viewHolder.itemName=(TextView) convertView.findViewById(R.id.pop_item_name);
            viewHolder.itemMaxTemp=(TextView) convertView.findViewById(R.id.pop_item_max_temp);
            viewHolder.itemBodyTemp=(TextView) convertView.findViewById(R.id.pop_item_body_temp);
            viewHolder.itemSkinTemp=(TextView) convertView.findViewById(R.id.pop_item_skin_temp);
            viewHolder.itemStep=(TextView) convertView.findViewById(R.id.pop_item_step);
            viewHolder.itemCalories=(TextView) convertView.findViewById(R.id.pop_item_calories);
            viewHolder.itemDistance=(TextView) convertView.findViewById(R.id.pop_item_distance);
            viewHolder.itemHeartRate=(TextView) convertView.findViewById(R.id.pop_item_heart_rate);
//            viewHolder.itemSystolicBloodPressure=(TextView) convertView.findViewById(R.id.pop_item_systolic_blood_pressure);
//            viewHolder.itemDiastolicBloodPressure=(TextView) convertView.findViewById(R.id.pop_item_diastolic_blood_pressure);
            viewHolder.itemBloodOxygen=(TextView) convertView.findViewById(R.id.pop_item_blood_oxygen);
            viewHolder.itemTime=(TextView) convertView.findViewById(R.id.pop_item_time);

            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        //从list取出对象
        IconBean bean = mList.get(position);
        //设置item的内容
        viewHolder.itemName.setText(bean.getItemName());
        viewHolder.itemMaxTemp.setText(bean.getItemMaxTemp());
        viewHolder.itemBodyTemp.setText(bean.getItemBodyTemp());
        viewHolder.itemSkinTemp.setText(bean.getItemSkinTemp());
        viewHolder.itemStep.setText(bean.getItemStep());
        viewHolder.itemCalories.setText(bean.getItemCalories());
        viewHolder.itemDistance.setText(bean.getItemDistance());
        viewHolder.itemHeartRate.setText(bean.getItemHeartRate());
//        viewHolder.itemSystolicBloodPressure.setText(bean.getItemSystolicBloodPressure());
//        viewHolder.itemDiastolicBloodPressure.setText(bean.getItemDiastolicBloodPressure());
        viewHolder.itemBloodOxygen.setText(bean.getItemBloodOxygen());
        viewHolder.itemTime.setText(bean.getItemTime());
        return convertView;
    }

    private static class ViewHolder{

        private TextView itemName;
        private TextView itemMaxTemp;
        private TextView itemBodyTemp;
        private TextView itemSkinTemp;
        private TextView itemStep;
        private TextView itemCalories;
        private TextView itemDistance;
        private TextView itemHeartRate;
        private TextView itemSystolicBloodPressure;
        private TextView itemDiastolicBloodPressure;
        private TextView itemBloodOxygen;
        private TextView itemTime;
    }
}
